package com.sjzd.entity;


import com.sjzd.ConfigParser;

import java.awt.*;

/**
 *  炮筒实体
 *
 */
public class Gun extends AbstractBase {
    private Direction direction = Direction.UP; // 方向

    public Gun(int X, int Y, int speed) {
      super(X, Y, speed);
    }

    // 炮筒的方向需要随着鼠标或者键盘的控制而改变
    @Override
    void draw(AbstractBase abstractBase, ConfigParser configParser, Graphics g) {
        int gunLength =  configParser.getGUN_LENGTH();
        if (abstractBase instanceof Tank) {
            Tank tank = (Tank) abstractBase;
            // 获取炮筒的终点位置
            int desX = tank.getGun().X + (int)Math.round(gunLength * sinX);
            int desY = tank.getGun().Y + (int)Math.round(gunLength * sinY);
            g.setColor(Color.BLACK);
            g.drawLine(tank.getGun().X, tank.getGun().Y,
                    desX, desY);
        }
    }

    @Override
    Rectangle getRectangle() {
        return null;
    }

    public Direction getDirection() {
        return direction;
    }

    public void setDirection(Direction direction) {
        this.direction = direction;
    }
}
